themingbackground: Add a quick exit for default case
authorBenjamin Otte <otte@redhat.com>
Wed, 8 Oct 2014 03:19:07 +0000 (05:19 +0200)
committerBenjamin Otte <otte@redhat.com>
Wed, 8 Oct 2014 03:20:31 +0000 (05:20 +0200)
In the case where the background is completely transparent, exit the
rendering functions before doing any expensive calculations.

gtk/gtkcsstypesprivate.h
gtk/gtkthemingbackground.c

index f3c319c3b3e45a60c26f4a4292e17e7cdfcc342a..314d3dd0ce9c43cd927423b4b94aaf7666938857 100644 (file)
@@ -280,6 +280,9 @@ GtkCssChange            _gtk_css_change_for_child                (GtkCssChange
 GtkCssDependencies      _gtk_css_dependencies_union              (GtkCssDependencies first,
                                                                   GtkCssDependencies second);
 
+/* for lack of better place to put it */
+/* mirror what cairo does */
+#define gtk_rgba_is_clear(rgba) ((rgba)->alpha < ((double)0x00ff / (double)0xffff))
 
 G_END_DECLS
 
index e85f9ae5e27156cf8047b114fc13970167414c86..acc830f331949b6d23473c7b3f5308264c04d8a0 100644 (file)
@@ -305,14 +305,20 @@ gtk_theming_background_render (GtkStyleContext      *context,
   GtkCssValue *box_shadow;
   const GdkRGBA *bg_color;
 
-  bg.context = context;
+  background_image = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BACKGROUND_IMAGE);
+  bg_color = _gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BACKGROUND_COLOR));
+  box_shadow = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_BOX_SHADOW);
+
+  /* This is the common default case of no background */
+  if (gtk_rgba_is_clear (bg_color) &&
+      _gtk_css_array_value_get_n_values (background_image) == 1 &&
+      _gtk_css_image_value_get_image (_gtk_css_array_value_get_nth (background_image, 0)) == NULL &&
+      _gtk_css_shadows_value_is_none (box_shadow))
+    return;
 
+  bg.context = context;
   _gtk_theming_background_init_context (&bg, width, height, junction);
 
-  background_image = _gtk_style_context_peek_property (bg.context, GTK_CSS_PROPERTY_BACKGROUND_IMAGE);
-  bg_color = _gtk_css_rgba_value_get_rgba (_gtk_style_context_peek_property (bg.context, GTK_CSS_PROPERTY_BACKGROUND_COLOR));
-  box_shadow = _gtk_style_context_peek_property (bg.context, GTK_CSS_PROPERTY_BOX_SHADOW);
-
   cairo_save (cr);
   cairo_translate (cr, x, y);